<?php
/*
 * showItems File
 *
 * @link http://riedel-st.de
 * @author Stefan Riedel <sr@riedel-st.de>
 * @todo das Tabelle Geraffel auslagern in ein Widget, da wir eh immer das selbe machen!
 */
?>
<h4><?=Yii::t('crm', 'Objekt Übersicht')?></h4>
<div id="showTable">
<table border="0" cellspacing="2" cellpadding="0" class="ui-widget-content ui-corner-all">
    <thead class="ui-widget-header">
        <tr>
            <th><?=Yii::t('crm', 'Name')?></th>
            <th><?=Yii::t('crm', 'Typ')?></th>
            <th><?=Yii::t('crm', 'Beschreibung')?></th>
            <th> </th>
        </tr>
    </thead>
    <?php foreach($result as $n => $item):?>
    <tr id="tr-<?=CHtml::encode($item->name)?>" class="state-default<?=$n%2?> js-changer">
        <td id="td-name-<?=CHtml::encode($item->name)?>"><?=($item->name === Yii::app()->dbConfig->superUser) ? CHtml::tag('strong', array('class' => 'icon superUser'), CHtml::encode($item->name)) : CHtml::encode($item->name)?></td>
        <td id="td-type-<?=CHtml::encode($item->name)?>"><?=CHtml::encode(Item::model()->getType($item->type))?></td>
        <td id="td-description-<?=CHtml::encode($item->name)?>"><?=CHtml::encode($item->description)?></td>
        <td id="td-actions-<?=CHtml::encode($item->name)?>">
        <?=(true === Yii::app()->user->checkAccess('CoreAuthEdit', array('id' => $item->name))) ? CHtml::ajaxLink(CRMHtml::image(CRMHtml::imageUrl('edit.png'), Yii::t('crm', 'Objekt bearbeiten'), array('title' => Yii::t('crm', 'Objekt bearbeiten'))), array('edit', 'id' => $item->name), array(
            'type'=>'GET',
            'update' => '#addItems',
            'beforeSend' => 'function(){
                $(".ui-tabs-selected a:first-child").addClass("preloader");
            }',
            'complete' => 'function(){
                $(".ui-tabs-selected a:first-child").removeClass("preloader");
                $("#items_panel").tabs({selected:1});
            }',
        ), array('id' => 'edit-'.$item->name)) : ''?>
        <?= ($item->name === Yii::app()->dbConfig->superUser) ? '' : CHtml::ajaxLink(CRMHtml::image(CRMHtml::imageUrl('delete.png'), Yii::t('crm', 'Objekt löschen'), array('title' => Yii::t('crm', 'Objekt löschen'))), array('delete', 'id' => $item->name), array(
            'type'=>'GET',
            'update' => '#showItems',
            'beforeSend' => 'function(){
                $(".ui-tabs-selected a:first-child").addClass("preloader");
            }',
            'complete' => 'function(){
                $(".ui-tabs-selected a:first-child").removeClass("preloader");
            }',
        ), array('id' => 'delete-'.$item->name))?>
        </td>
    </tr>
    <?php endforeach; ?>
</table>
</div>